﻿using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using GraphDrawing2.V2.Concrete.Model;

namespace GraphDrawing2.Canvas
{
    public class CanvasModel
    {
        readonly Dictionary<PaintStage, List<IPainter>> painterStages = new Dictionary<PaintStage, List<IPainter>>();

        public ViewPortModel ViewPort { get; private set; }

        public Point MousePosition { get; private set; }

        public MouseButtons MouseButtons { get; private set; }

        public Keys Keys { get; private set; }

        public IList<IListener> Listeners { get; private set; }

        public CanvasModel()
        {
            painterStages[PaintStage.BACKGROUND] = new List<IPainter>();
            painterStages[PaintStage.CONTENT] = new List<IPainter>();
            painterStages[PaintStage.POSTPROCESSING] = new List<IPainter>();
            Listeners = new List<IListener>();
            ViewPort = new ViewPortModel();
        }

        public void AddPainter(PaintStage stage, IPainter painter)
        {
            painterStages[stage].Add(painter);
        }

        public void RemovePainter(PaintStage stage, IPainter p)
        {
            painterStages[stage].Remove(p);
        }

        public IEnumerable<IPainter> GetPainters(PaintStage stage)
        {
            return painterStages[stage];
        }

        public void UpdateState(Point coord, MouseButtons buttons, Keys keystate)
        {
            MousePosition = coord;
            MouseButtons = buttons;
            Keys = keystate;
        }
    }
}